package com.whty.cms.filewps.common.message;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.whty.cms.filewps.common.constants.Consts;

import java.io.Serializable;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseMessage implements Serializable {

	private static final long serialVersionUID = 1L;
	
	private String code;

	private String msg;

	private Object data;

	public ResponseMessage success() {
		this.code = Consts.SUCCESS_CODE;
		this.msg = Consts.SUCCESS_MESSAGE;
		return this;
	}

	public ResponseMessage failed() {
		this.code = Consts.FAILED_CODE;
		this.msg = Consts.FAILED_MESSAGE;
		return this;
	}

	public static ResponseMessage getSuccessResponse() {
		ResponseMessage response = new ResponseMessage();
		response.setCode(Consts.SUCCESS_CODE);
		response.setMsg(Consts.SUCCESS_MESSAGE);
		return response;
	}

	public static ResponseMessage getFailedResponse() {
		ResponseMessage response = new ResponseMessage();
		response.setCode(Consts.FAILED_CODE);
		response.setMsg(Consts.FAILED_MESSAGE);
		return response;
	}

	public static ResponseMessage getResponse(String code, String msg) {
		ResponseMessage response = new ResponseMessage();
		response.setCode(code);
		response.setMsg(msg);
		return response;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public static ResponseMessage returnMessage(ResponseMessage result, String code, String msg, Object data) {
		result.setCode(code);
		result.setMsg(msg);
		result.setData(data);
		return result;
	}
	
}
